package com.boyue.web.controller;

import com.boyue.entity.SysUser;
import com.boyue.service.SysUserService;
import com.boyue.service.impl.SysUserServiceImpl;
import com.boyue.utils.AjaxResult;
import com.boyue.utils.PageInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @auth wzy
 * @date 2023/9/6 16:24
 */
public class SysUserController {

    private SysUserService sysUserService = new SysUserServiceImpl();

    public AjaxResult login(HttpServletRequest request, HttpServletResponse response){

        String username = request.getParameter("username");
        String password = request.getParameter("password");

        try {
            SysUser sysUser = sysUserService.login(username, password);
            return AjaxResult.success(sysUser);
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }

    public Object list(HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> tableMap = new HashMap<String,Object>();


        PageInfo pageInfo = new PageInfo<SysUser>();
        pageInfo.setPageIndex(Integer.valueOf(request.getParameter("page")));
        pageInfo.setPageSize(Integer.valueOf(request.getParameter("limit")));

       sysUserService.listPage(pageInfo);

        tableMap.put("code",0);
        tableMap.put("count",pageInfo.getCount());
        tableMap.put("data",pageInfo.getPageList());
        tableMap.put("msg","");


        return tableMap;
    }
}
